//
//  BaseViewController.m
//  Project
//
//  Created by 冯东辉 on 2018/9/12.
//  Copyright © 2018年 FengDongHui. All rights reserved.
//

#import "BaseViewController.h"
#import "UIBarButtonItem+Extension.h"

#import "UINavigationBar+handle.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.view.backgroundColor = UICOLOR_HEX(0xffEDEEEF);
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
//    [self.navigationController.navigationBar setTitleTextAttributes:@{
//                                                                      NSFontAttributeName:[UIFont systemFontOfSize:16],
//                                                                      NSForegroundColorAttributeName:UICOLOR_HEX(0xffffffff)
//                                                                      }];
    
    _navTitleL = [[UILabel alloc] initWithFrame:CGRectMake(80, SafeAreaTopHeight-44, GET_SCREEN_WIDTH()-80*2, 44)];
    _navTitleL.textAlignment = NSTextAlignmentCenter;
    _navTitleL.font = [UIFont systemFontOfSize:16];
    _navTitleL.textColor = UICOLOR_HEX(0xffffffff);
    self.navigationItem.titleView = _navTitleL;
    
    [self setNeedsStatusBarAppearanceUpdate];
}

- (void)setFontSizeThatFits:(UILabel*)label {
    
    CGFloat fontSizeThatFits;
    
    [label.text sizeWithFont:label.font
                 minFontSize:8.0
              actualFontSize:&fontSizeThatFits
                    forWidth:label.bounds.size.width
               lineBreakMode:NSLineBreakByWordWrapping];
    
    label.font = [label.font fontWithSize:fontSizeThatFits];
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
}

- (void)viewWillLayoutSubviews {
    
    [super viewWillLayoutSubviews];
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    self.navigationController.navigationBar.alpha = 1.0f;
    [self.navigationController.navigationBar setBackgroundColor:Base_color];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
    
/**
 建立蓝色样式的导航栏
 */
-(void)createBlueNavigationBar:(BOOL)isNeedBack {
    
    [self.navigationController.navigationBar navBarBackGroundColor:Base_color image:nil isOpaque:YES];
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    
    if (isNeedBack == YES) {
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImageName:@"nav_back" higImageName:@"nav_back" action:@selector(leftNavigationBarButtonClick) target:self];
    }
}

/**
 导航栏返回事件
 */
-(void)leftNavigationBarButtonClick {
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
